﻿using Bear.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Bear
{
    public partial class ConfigForm : Form
    {
        AppConfig config = null;
        public ConfigForm()
        {
            InitializeComponent();
            this.RegisterEvent();
        }

        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            config = AppConfig.Load();

            this.tbAccountName.Text = config.AccountName;
            this.tbAccountPassword.Text = config.AccountPassword;
            this.tbGamePath.Text = config.GamePath;
            this.tbSecurityCode.Text = config.SecurityCode;
            this.cbIsDebug.Checked = config.IsDebug;
            this.numChannel.Value = config.Channel;
            this.numRole.Value = config.Role;
        }

        private void RegisterEvent()
        {
            this.btnSave.Click += (sender, e) =>
            {
                config.AccountName = this.tbAccountName.Text;
                config.AccountPassword = this.tbAccountPassword.Text;
                config.GamePath = this.tbGamePath.Text;
                config.SecurityCode = this.tbSecurityCode.Text;
                config.IsDebug = this.cbIsDebug.Checked;
                config.Channel = Convert.ToInt32(this.numChannel.Value);
                config.Role = Convert.ToInt32(this.numRole.Value);
                config.Save();
                this.Close();
            };
            this.btnClose.Click += (sender, e) =>
            {
                this.Close();
            };
        }
    }
}
